﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace QuanLyDuAn.Report
{
    public partial class FrmInterviewDepartment : DevComponents.DotNetBar.Office2007Form
    {
        public String value;
        ReportDocument cryRpt;
        public FrmInterviewDepartment()
        {
            InitializeComponent();
        }

        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            cryRpt = new ReportDocument();
            cryRpt.Load(@"E:\Studying\Quản trị dự án\Project\QuanLyDuAn\QuanLyDuAn\Report\InterviewDepartment.rpt");

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = value;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["iDepartment"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh(); 
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            String month = DateTime.Now.Month.ToString();
            String year = DateTime.Now.Year.ToString();
            String day = DateTime.Now.Day.ToString();
            String hour = DateTime.Now.Hour.ToString();
            String minutes = DateTime.Now.Minute.ToString();
            String datetime = day + "_" + month + "_" + year + "_" + hour + "h" + minutes;
            try
            {
                ExportOptions CrExportOptions;

                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                ExcelFormatOptions CrFormatTypeOptions = new ExcelFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = "c:\\Interviewer_"+value+" "+datetime+".xls";
                CrExportOptions = cryRpt.ExportOptions;
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType = ExportFormatType.Excel;
                CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions = CrFormatTypeOptions;
                cryRpt.Export();
                MessageBox.Show("Export successful !");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void FrmInterviewDepartment_Load(object sender, EventArgs e)
        {

        }
    }
}
